package com.ruoyi.flats.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.flats.domain.Flats;
import com.ruoyi.flats.service.IFlatsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公寓管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/flats/flats")
public class FlatsController extends BaseController
{
    @Autowired
    private IFlatsService flatsService;

    /**
     * 查询公寓管理列表
     */
    @PreAuthorize("@ss.hasPermi('flats:flats:list')")
    @GetMapping("/list")
    public TableDataInfo list(Flats flats)
    {
        startPage();
        List<Flats> list = flatsService.selectFlatsList(flats);
        return getDataTable(list);
    }

    /**
     * 导出公寓管理列表
     */
    @PreAuthorize("@ss.hasPermi('flats:flats:export')")
    @Log(title = "公寓管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Flats flats)
    {
        List<Flats> list = flatsService.selectFlatsList(flats);
        ExcelUtil<Flats> util = new ExcelUtil<Flats>(Flats.class);
        util.exportExcel(response, list, "公寓管理数据");
    }

    /**
     * 获取公寓管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('flats:flats:query')")
    @GetMapping(value = "/{flatId}")
    public AjaxResult getInfo(@PathVariable("flatId") Long flatId)
    {
        return success(flatsService.selectFlatsByFlatId(flatId));
    }

    /**
     * 新增公寓管理
     */
    @PreAuthorize("@ss.hasPermi('flats:flats:add')")
    @Log(title = "公寓管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Flats flats)
    {
        return toAjax(flatsService.insertFlats(flats));
    }

    /**
     * 修改公寓管理
     */
    @PreAuthorize("@ss.hasPermi('flats:flats:edit')")
    @Log(title = "公寓管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Flats flats)
    {
        return toAjax(flatsService.updateFlats(flats));
    }

    /**
     * 删除公寓管理
     */
    @PreAuthorize("@ss.hasPermi('flats:flats:remove')")
    @Log(title = "公寓管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flatIds}")
    public AjaxResult remove(@PathVariable Long[] flatIds)
    {
        return toAjax(flatsService.deleteFlatsByFlatIds(flatIds));
    }
}
